﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace hlavny.modul2
{
    public partial class CreateDatabaseForm : Form
    {
        public CreateDatabaseForm()
        {
            InitializeComponent();
            labelError.Visible = false;
            textBoxDbName.Focus();
        }

        private void ErrorMessage(string message)
        {
            buttonAddDatabase.Location = new Point(84, 60);
            labelError.Visible = true;
            labelError.Text = message;
            textBoxDbName.Focus();
            textBoxDbName.SelectAll();
        }

        private void buttonAddDatabase_Click(object sender, EventArgs e)
        {
            if (CFunctions.IsValidName(textBoxDbName.Text))
            {
                if (!CDBS.SysDatabases.ContainDatabaseName(textBoxDbName.Text))
                {
                    CDBS.SysDatabases.CreateDB(textBoxDbName.Text);
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    ErrorMessage("Databáza so zadaným názvom uz existuje!");
                }
            }
            else
            {
                ErrorMessage("Zadali ste neplatný názov!");
            }
        }
    }
}
